#!/bin/bash
#
# Retrieves context information from the system
#
# Author:   Dr. Mike Murphy (mmurphy2@coastal.edu)
# Revision: 19 November 2013
#
#   Copyright 2012-2013 Coastal Carolina University
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.
#


## p_cmd_get_context_help
##
## Echoes help information for the get_context command. Returns 0.
##
function p_cmd_get_context_help() {
	cat << EOF
Usage: pulley get_context <item> [default value]

Retrieves and prints to standard output the value of the context entry <item>.
If no such context entry exists, and no [default value] is given, no output
will be printed. The exit status of this command will be 0 if the context
item is found, or non-zero if falling back to the [default value].
EOF
	return 0
}


## p_cmd_get_context_summary
##
## Echoes summary information for the get_context command. Returns 0.
##
function p_cmd_get_context_summary() {
	echo "Retrieves context information from the system"
	return 0
}


## p_cmd_get_context <item>
##
## Implements the get_context command, printing the context information to
## standard output. Returns 0 on success, 2 if <item> is omitted or the
## context path in <item> is invalid, or another non-zero value if an error
## occurs.
##
function p_cmd_get_context() {
	local status=0
	
	if [[ $# -lt 1 ]]; then
		echo "Usage: pulley get_context <item> [default value]"
		status=2
	else
		get_context "$1" "$2"
		status=$?
	fi
	
	return ${status}
}
